<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head> 
   <meta charset="UTF-8">
   <%@ include file="/WEB-INF/views/include/head.jsp"%>
   <link rel="stylesheet" href="${ctxStatic}/css/common_erp.css">
   <link rel="stylesheet" href="${ctxStatic}/css/layerSm.css">
   <script src="${ctxStatic}/js/jquery-1.9.1.min.js"></script>
   <script src="${ctxStatic}/js/layer.js"></script>
   <script src="${ctxStatic}/js/style.js"></script>
   <script src="${ctxStatic}/jquery-barcode/jquery-barcode.js" type="text/javascript"></script>
   <c:set value="<%=ResourcesUtil.getConfig(\"outbound_status_not_all\")%>" var="inventoryStatusNotAll" />
   <c:set value="<%=ResourcesUtil.getConfig(\"outbound_status_all\")%>" var="inventoryStatusAll" />
   <script type="text/javascript">
      $(document).ready(function(){
         $("#inventoryRequestBarCodeDiv").empty().barcode($("#stockBarCode").val(), "code128",{barWidth:2, barHeight:30,showHRI:false});
      	 $("#contractID").select2();
      	$("#contractID").attr("disabled",true);
      });
      
      /* 刷新明细  */
      function requestDetails() {
    	  var id ="${materialOutInbound.id}";
    	  var inventoryRequestNo ="${materialOutInbound.inventoryRequestNo}";
      	param={"id":id,"inventoryRequestNo":inventoryRequestNo};
      	$.post("${ctx}/material/outbound/show",param,function(result){ 
          	$("#tableRequestDetails").html($(callBackHtml(result)).find("#tableRequestDetails").html());
          	tryToCgStatus();
          },'html');
  	}
      /* 试图更改入库状态  */
      function tryToCgStatus() {
		var length = $(".realQuantity").length;
		var sumResult = parseFloat(0);
		var reResult = parseFloat(0);
		for (var i = 0; i < length; i++) {
			var realQuantity = $(".realQuantity")[i].innerHTML;
			if (realQuantity==""||realQuantity==null) {
				return;
			}
			realQuantity = realQuantity.replace(/,/g,"");
			sumResult += parseFloat(realQuantity);
		}
		for (var i = 0; i < length; i++) {
			var requestQuantity = $(".requestQuantity")[i].innerHTML;
			if (requestQuantity==""||requestQuantity==null) {
				requestQuantity = "0";
			}
			requestQuantity = requestQuantity.replace(/,/g,"");
			reResult += parseFloat(requestQuantity);
		}
		var inventoryStatus = "";
		if (reResult>sumResult) {
			inventoryStatus = "${inventoryStatusNotAll}";
		}else if(reResult<=sumResult){
			inventoryStatus = "${inventoryStatusAll}";
		}
		var id = "${materialOutInbound.id}";
		var params = {"id":id,"inventoryStatus":inventoryStatus};
		$.post("${ctx}/material/outbound/changeStatus",params,function(result){    
			window.parent.frames[0].searchListForm();
          },'html');
	}
      
	</script>
</head>
<body>
<div class="layerHeader clearfix">
<input type="hidden" id="inventoryRequestNo" value="${materialOutInbound.inventoryRequestNo}"/>
<!-- 物料出库 -->
	<p class="headerTitle"><spring:message code="inventory_requestex_create_materialInventory"/></p>
    <div class="headerButton clearfix">
        <!-- 取消 -->
        <button onclick="closeWin()"><spring:message code="btn_cancle"/></button>
    </div>
</div>
<div class="smOrderBox">
    <div class="items clearfix">
        <div class="col-33 clearfix">
            <!-- 出库单号 -->
            <p class="tit"><spring:message code="inventory_requestex_create_requestNo"/></p>
            <p>${materialOutInbound.inventoryRequestNo}</p>
        </div>
        <div class="col-33 clearfix">
            <!-- 申请人 -->
            <p class="tit"><spring:message code="inventory_requestex_create_requestUser"/></p>
            <p>${materialOutInbound.requestUser}</p>
        </div>
        <div class="col-33 clearfix">
            <!-- 申请日期 -->
            <p class="tit"><spring:message code="inventory_requestex_create_requestDate"/></p>
            <p><fmt:formatDate value="${materialOutInbound.requestDate}" pattern="yyyy-MM-dd" /></p>
        </div>
    </div>
    <div class="items clearfix">
        <div class="col-33 clearfix">
            <!-- 出库类别 -->
            <p class="tit"><spring:message code="inventory_requestex_create_inventoryCategory"/></p>
            <p>${fns:getDictName(materialOutInbound.inventoryCategory)}</p>
        </div>
        <c:if test="${imageStr == 'customizationUnitCost' }">
        <div class="col-33 clearfix haveToBox">
		    <!-- 定制合同号 -->
		    <p class="tit"><spring:message code="unitCost_export_select_contractNo"/></p>
			<div class="timeBox">
				<select id="contractID" style="width: 180px;">
					<option value=""><spring:message code="unitCost_export_select_pleaseChoose"/></option>
					<c:forEach items="${contractList }" var="ct">
						<option value="${ct.contractID }" <c:if test="${materialOutInbound.contractID == ct.contractID }">selected="selected"</c:if>>${ct.contractNo }</option>
					</c:forEach>
				</select> 
			</div>
        </div>
        </c:if>
        
    </div>
    <c:if test="${imageStr != 'customizationUnitCost' }">
    <div class="items clearfix">
	    <c:if test="${materialOutInbound.inventoryCategory == 'OUTBOUND_CATEGORY-PUTTING' }">
	        <div class="col-33 clearfix">
	            <!-- 加工厂名称-->
	            <p class="tit"><spring:message code="inventory_requestex_create_fabricatingName"/></p>
	            <p>${materialOutInbound.fabricatingName}</p>
	        </div>
	        <div class="col-33 clearfix">
	            <!-- 外发订单 -->
	            <p class="tit" style="width: 75px;"><spring:message code="inventory_requestex_create_puttingNo"/></p>
	            <p>${materialOutInbound.contractProcessNo}</p>
	        </div>
	    </c:if>
	    <c:if test="${materialOutInbound.inventoryCategory == 'OUTBOUND_CATEGORY-PRODUCE' }">
	    	<div class="col-33 clearfix">
	            <!-- 客户名称 -->
	            <p class="tit">客户名称</p>
	            <p>${materialOutInbound.venderName}</p>
	        </div>
	        <div class="col-33 clearfix">
	            <!-- 客户订单号 -->
	            <p class="tit" style="width: 75px;">客户订单号</p>
	            <p>${materialOutInbound.indentNo}</p>
	        </div>
	    </c:if>
        <div class="clearfix">
            <!-- 款式 -->
            <p class="tit"><spring:message code="inventory_requestex_create_styleNoName"/></p>
            <p>${materialOutInbound.styleCustomerNo}&ensp;${materialOutInbound.styleName}</p>
        </div>
    </div>
    </c:if>
</div>
<div class="tableArea">
    <div class="tableScrollSm" <c:if test="${imageStr == 'customizationUnitCost' }">style="overflow:auto;width:888px;height:440px;"</c:if><c:if test="${imageStr != 'customizationUnitCost' }">style="overflow:auto;width:888px;height:400px;"</c:if>>
        <table cellpadding="0" class="tableHead">
            <thead>
            <tr>
                <!-- 操作 -->
                <th style="width:50px;"><spring:message code="inventory_requestex_create_details_operate"/></th>
                <!-- 物料图片 -->
                <th class="width-70px"><spring:message code="inventory_requestex_create_details_img"/></th>
                <!-- 名称编码 -->
                <th><p class="width-165px"><spring:message code="inventory_requestex_create_details_nameCode"/></p></th>
                <!-- 物料类别 -->
                <th><p class="width-70px"><spring:message code="inventory_requestex_create_details_type"/></p></th>
                <!-- 幅宽 -->
                <th><p class="width-70px"><spring:message code="inventory_requestex_create_details_spec"/></p></th>
                <!-- 成分 -->
                <th><p class="width-70px"><spring:message code="inventory_requestex_create_details_composition"/></p></th>
                <!-- 颜色 -->
                <th><p class="width-70px"><spring:message code="inventory_requestex_create_details_color"/></p></th>
                <!-- 库存数量 -->
                <th class="width-100px"><spring:message code="inventory_requestex_create_details_materialQuantity"/></th>
                <!-- 申请出库数量 -->
                <th class="width-100px"><spring:message code="inventory_requestex_create_details_requestQuantity"/></th>
                <!-- 实际出库数量 -->
                <th class="width-100px"><spring:message code="inventory_requestex_create_details_realQuantity"/></th>
            </tr>
            </thead>
        </table>
        <table cellpadding="0" class="tableBody" id="tableRequestDetails">
            <tbody>
        <c:if test="${not empty materialOutInbound.requestDetailsList}">
            <c:forEach items="${materialOutInbound.requestDetailsList}" var="requestDetailsInfo" varStatus="status">
            <tr>
                <td style="width:50px;"><img src="${ctxStatic}/images/btn-bj.png" onclick="popup('800px','519px','${ctx}/material/outbound/materialDetailList?id=${materialOutInbound.id}&requestQuantity=${requestDetailsInfo.requestQuantity}&inventoryDetailId=${requestDetailsInfo.inventoryDetailId}&materialCode=${requestDetailsInfo.materialCode}&materialNameCn=${requestDetailsInfo.materialNameCn}&inventoryInOutKbn=${materialOutInbound.inventoryInOutKbn }&inventoryCategory=${materialOutInbound.inventoryCategory }&inventoryStatus=${materialOutInbound.inventoryStatus }&materialId=${requestDetailsInfo.materialId}')" height="30" width="30"></td>
                <td class="width-70px">
                  <c:if test="${not empty requestDetailsInfo.filePath}">
                        <img src="${requestDetailsInfo.filePath}" class="wltp">
                  </c:if>
                  <c:if test="${empty requestDetailsInfo.filePath}">
                        <img src="${ctxStatic}/images/pic-none.jpg" class="wltp">
                  </c:if>
                </td>
                <td><p class="width-165px"><c:if test="${imageStr != 'customizationUnitCost' }">${requestDetailsInfo.materialNameCn}<br></c:if>${requestDetailsInfo.materialCode}</p></td>
                <td><p class="width-70px">${fns:getDictName(requestDetailsInfo.materialCategory)}</p></td>
                <td><p class="width-70px">${requestDetailsInfo.materialSpec}</p></td>
                <td><p class="width-70px">${requestDetailsInfo.materialComposition}</p></td>
                <td><p class="width-70px">${requestDetailsInfo.materialColor}</p></td>
                <td class="subDetails width-100px"><fmt:formatNumber value="${requestDetailsInfo.materialQuantity}" pattern="#,##0.###"/></td>
                <td class="subDetails width-100px requestQuantity"><fmt:formatNumber value="${requestDetailsInfo.requestQuantity}" pattern="#,##0.###"/></td>
                <td class="subDetails width-100px realQuantity"><fmt:formatNumber value="${requestDetailsInfo.realQuantity}" pattern="#,##0.###"/></td>
            </tr>
            </c:forEach>
            </c:if>
            </tbody>
        </table>
    </div>
</div>
</body>
</html>